package org.springcloud.wisdom.amusement.service.serviceimp;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springcloud.wisdom.amusement.dao.AmusementNoticeDao;
import org.springcloud.wisdom.amusement.entity.AmusementNotice;
import org.springcloud.wisdom.amusement.service.IAmusementNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AmusementNoticeServiceImp implements IAmusementNoticeService {
    @Autowired
    AmusementNoticeDao amusementNoticeDao;

//    @Override
//    public List<AmusementNotice> seeAllNotice() {
//        return amusementNoticeDao.selectNotice();
//    }
//
//    @Override
//    public List<AmusementNotice> seeTeamNotice(Integer teamid) {
//        if (teamid == null) return null;
//        return amusementNoticeDao.selectTeamNotice(teamid);
//    }

//    @Override
//    public IPage<AmusementNotice> seeTeamNoticePage(int currentPage, int size, Integer teamid) {
//        Page<AmusementNotice> pageRequest = new Page<>(currentPage, size);
//        IPage<AmusementNotice> seeTeamNoticePage = amusementNoticeDao.selectTeamNoticePage(pageRequest,teamid);
//        return seeTeamNoticePage;
//    }

//    @Override
//    public IPage<AmusementNotice> selectPubNoticePage(int currentPage, int size, Integer teamid) {
//        Page<AmusementNotice> pageRequest = new Page<>(currentPage, size);
//        IPage<AmusementNotice> selectPubNoticePage = amusementNoticeDao.selectPubNoticePage(pageRequest,teamid);
//        return selectPubNoticePage;
//    }

    @Override
    public IPage<AmusementNotice> seeUnNoticePage(int currentPage, int size) {
        Page<AmusementNotice> pageRequest = new Page<>(currentPage, size);
        IPage<AmusementNotice> seeUnNoticePage = amusementNoticeDao.selectUnPubNoticePage(pageRequest);
        return seeUnNoticePage;
    }

    @Override
    public Boolean deleteNotice(Integer id) {
        if (id == null) return false;
        return amusementNoticeDao.deleteNotice(id) > 0;
    }

    @Override
    public Boolean addNotice(AmusementNotice amusementNotice) {
        if (amusementNotice.getTitle().trim().length()==0 || amusementNotice.getTitle()==null){
            return false;
        }
        if (amusementNotice.getContent().trim().length()==0 || amusementNotice.getContent()==null){
            return false;
        }
        if (amusementNotice.getIdentity().trim().length()==0 || amusementNotice.getIdentity()==null){
            return false;
        }
        if (amusementNotice.getType() == null){
            return  false;
        }
             return amusementNoticeDao.addNotice(amusementNotice) > 0;
    }

    @Override
    public Boolean realAddNotice(AmusementNotice amusementNotice) {
        if (amusementNotice.getId() == null){
            return  false;
        }
        return amusementNoticeDao.realAddNotice(amusementNotice.getId()) > 0;
    }

    @Override
    public Boolean rejectNotice(AmusementNotice amusementNotice) {
        if (amusementNotice.getReason().trim().length()==0 || amusementNotice.getReason()==null){
            return false;
        }
        if (amusementNotice.getId() == null){
            return  false;
        }
        return amusementNoticeDao.rejectNotice(amusementNotice) > 0;
    }
}
